package org.rule.function;

import cn.hutool.core.util.StrUtil;
import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorBoolean;
import com.googlecode.aviator.runtime.type.AviatorObject;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class ListInFunction extends AbstractFunction{
    private static final String regex = ",";
    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        String str1 = FunctionUtils.getStringValue(arg1, env);
        String str2 = FunctionUtils.getStringValue(arg2,env);
        List<String> list = Arrays.stream(str2.split(regex)).toList();
        return AviatorBoolean.valueOf(list.contains(str1));
    }
    @Override
    public String getName() {
        return "list_in";
    }
}
